﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Milan.Diagnostics;

namespace Milan.Forms
{
	public partial class LogDisplay : Form
	{
		public LogDisplay()
		{
			InitializeComponent();
		}
		public static void ThrowUp()
		{
			m_started = new ManualResetEvent(false);
			m_thread = new Thread(MainThread);
			m_thread.IsBackground = true;
			m_thread.TrySetApartmentState(ApartmentState.STA);
			m_thread.Start();
			m_started.WaitOne();
		}
		delegate void CloseDelegate();
		public static void TakeDown()
		{
			if(m_thread.IsAlive)
				Current.Invoke(new CloseDelegate(Current.Close));
		}

		private void LogDisplay_Load(object sender, EventArgs e)
		{
			var scr = Screen.FromPoint(Location);
			Location = new Point(scr.WorkingArea.Right - Width, scr.WorkingArea.Bottom - Height);
			m_started.Set();
		}
		private static void MainThread(object param)
		{
			Current = new LogDisplay();
			System.Windows.Forms.Application.Run(Current);
		}
		private static LogDisplay Current;
		private static Thread m_thread;
		private static ManualResetEvent m_started = new ManualResetEvent(false);
	}
}
